from selenium import webdriver
import time
from hashlib import new
import step
from selenium import webdriver
from selenium.webdriver.chrome.webdriver import WebDriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from selenium import webdriver
from selenium.webdriver.common.keys import Keys

# 打开谷歌浏览器
driver = webdriver.Chrome()
print("浏览器最大化")
driver.maximize_window() #将浏览器最大化显示
driver.implicitly_wait(10) #隐藏等待

driver.refresh()

# 打开测试地址
driver.get("https://beta-actest.wesais.cn/#/login")
print("打开测试地址")

# 3、输入账号密码
driver.find_element(By.CLASS_NAME,'el-input__inner').send_keys('mo')
driver.find_element(By.NAME,'password').send_keys('Qq123456!')
time.sleep(1)   #等待1秒
print("输入账号密码")

# 4、点击登录
element = driver.find_element(By.CLASS_NAME, 'el-button')
driver.execute_script("arguments[0].click();", element)
time.sleep(3)   #等待1秒
print("登录成功")

# 5、点击场馆营业
# element = driver.find_element(By.XPATH, '/html/body/div[1]/div/div/section/div/div[2]/div/div[5]/div/img')
# driver.execute_script("arguments[0].click();", element)

elements = driver.find_elements(By.CLASS_NAME,'app-item')
for element in elements:
   c_element= element.find_element(By.TAG_NAME,"span")
   if '场馆营业' ==c_element.text:
       driver.execute_script("arguments[0].click();",c_element)

driver.save_screenshot('D:/Python_data/pythonProject/图片/进入系统.png')
time.sleep(2)   #等待2秒
print("点击场馆营业")

# 6、下拉场馆
handles = driver.window_handles
time.sleep(1)
driver.switch_to.window(handles[1])#跳转新开页签


element = driver.find_element(By.XPATH, '/html/body/div[1]/div/div[1]/div[1]/div/ul/div[1]/div/div')
driver.execute_script("arguments[0].click();", element)
time.sleep(2)
print("下拉场馆")

# 7、选择场馆
element = driver.find_element(By.XPATH, '/html/body/ul/li[5]/li[2]')
driver.execute_script("arguments[0].click();", element)
time.sleep(2)
print("选择场馆")

# 8、进入场馆
element = driver.find_element(By.XPATH, '/html/body/div[1]/div/div[1]/div[1]/div/ul/div[4]/li/div')
driver.execute_script("arguments[0].click();", element)
time.sleep(2)
print("进入场馆")

# 9、场地预定
element = driver.find_element(By.XPATH, '/html/body/div[1]/div/div[1]/div[1]/div/ul/div[4]/li/ul/div[1]/a/li/span')
driver.execute_script("arguments[0].click();", element)
time.sleep(5)
print("场地预定")



element = driver.find_element(By.XPATH, '/html/body/div/div/div[2]/section/div/div[1]/div[2]/div[1]/div/div[2]/div[3]')
driver.execute_script("arguments[0].click();", element)
time.sleep(5)
print("选择第二天的场地")
#
# links = driver.find_elements(By.LINK_TEXT, "5.00")
# if len(links) > 1:
#     links[1].click()
# time.sleep(5)
# print("选择场地")

# d = driver.find_elements(By.CLASS_NAME, 'opacity-color')
# # .board-data>.board-data-detail:nth-child(5)>div>div:nth-child(8)
# n =1
# line = driver.find_elements(By.CLASS_NAME, '.board-data>.board-data-detail:nth-child('+ n +')')
# line = driver.find_elements(By.CLASS_NAME, '.board-data>.board-data-detail:nth-child('+ y +')')
# print(len(d))
# d.c.click()


element = driver.find_element(By.XPATH, '//html/body/div/div/div[2]/section/div/div[1]/div[2]/div[2]/div[2]/div[2]/div[4]/div/div[9]/span')
driver.execute_script("arguments[0].click();", element)
time.sleep(3)
driver.save_screenshot('D:/Python_data/pythonProject/图片/场地信息.png')
print("点击会员框")

driver.find_element(By.XPATH,'//*[@id="app"]/div/div[2]/section/div/div[1]/div[2]/div[3]/form/div/section[3]/div[2]/div[2]/div[1]/div[2]/div/span/span/div/div/input').send_keys('18300062421')
# /html/body/div/div/div[2]/section/div/div[1]/div[2]/div[3]/form/div/section[3]/div[2]/div[2]/div[1]/div[2]/div/span/span/div/div/input
time.sleep(3)
print("输入会员卡号")

element = driver.find_element(By.XPATH, '/html/body/div[2]/ul/li[1]/div/div')
driver.execute_script("arguments[0].click();", element)
driver.save_screenshot('D:/Python_data/pythonProject/图片/会员卡信息.png')
time.sleep(3)
print("选择会员卡")

element = driver.find_element(By.XPATH, '/html/body/div/div/div[2]/section/div/div[1]/div[2]/div[3]/form/footer/div[2]/button[2]')
driver.execute_script("arguments[0].click();", element)
time.sleep(3)
driver.save_screenshot('D:/Python_data/pythonProject/图片/支付方式.png')
time.sleep(3)
print("预定")

element = driver.find_element(By.XPATH, '//*[@id="app"]/div/div[2]/section/div/div[2]/section/button[2]')
driver.execute_script("arguments[0].click();", element)
time.sleep(1)
print("确认支付")
time.sleep(5)
driver.save_screenshot('D:/Python_data/pythonProject/图片/支付结果.png')
print("支付成功")


